<template>
  <el-card>
    <div slot="header">
      <div class="title">
        <span>销售额占比</span>
        <div>
          <div>
            <el-radio-group v-model="value" size="small">
              <el-radio-button label="全部渠道"></el-radio-button>
              <el-radio-button label="线上"></el-radio-button>
              <el-radio-button label="门店"></el-radio-button>
            </el-radio-group>
          </div>
        </div>
      </div>
      <div ref="chearch" class="chearch"></div>
    </div>
  </el-card>
</template>

<script>
import echarts from 'echarts';

export default {
  data() {
    return {
      value: '全部渠道'
    }
  },

  mounted() {
    let myChart = echarts.init(this.$refs.chearch);
    myChart.setOption({
      title: {
        text: 'Search Engine',
        subtext: '1048',
        left: 'center',
        top: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      series: [
        {
          name: 'Access From',
          type: 'pie',
          radius: ['40%', '70%'],
          avoidLabelOverlap: false,
          itemStyle: {
            borderRadius: 10,
            borderColor: '#fff',
            borderWidth: 2
          },
          label: {
            show: true,
            position: 'outsice'
          },
          labelLine: {
            show: false
          },
          data: [
            { value: 1048, name: 'Search Engine' },
            { value: 735, name: 'Direct' },
            { value: 580, name: 'Email' },
            { value: 484, name: 'Union Ads' },
            { value: 300, name: 'Video Ads' }
          ]
        }
      ]
    });

    // 绑定事件
    myChart.on('mouseover', (params) => {
      // 获取鼠标移上去的属性
      const { name, value } = params.data;
      // 重新设置标题
      myChart.setOption({
        title: {
          text: name,
          subtext: value
        }
      })
    });
  }
}
</script>

<style scoped>
.title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

.chearch {
  width: 100%;
  height: 300px;
}
</style>